﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CLDataAppManagement;
using Newtonsoft.Json.Linq;

namespace TestDataFileManagerment
{
    internal class Program
    {
        static JToken jToken;
        static void Main(string[] args)
        {
            string jsonString =
                "{\r\n    \"root\": {\r\n        \"field1\": \"test1\",\r\n        \"field2\": \"test2\",\r\n        \"array1\": [ 1, 2, 3 ],\r\n        \"array2\": [ 11, 22, 33 ],\r\n        \"arrayClass\": [\r\n            { \"fieldClass1\": \"333\" },\r\n            { \"fieldClass2\": \"444\" },\r\n            { \"arrayarrayClass\": [ 55, 66 ] }\r\n        ]\r\n\r\n\r\n\r\n    }\r\n}";



            DataAppManagement dataAppManagement = new DataAppManagement();

            jToken = dataAppManagement.LoadFile(@"D:\New_Plug_In\Item9_DataApp_Development\3.0版本\CLDataAppManagement\TestDataFileManagerment\jsconfig1.json", out _, out _);

            //dataAppManagement.ModifyKey("root.field1", "field3", out _, out _);
            //dataAppManagement.ModifyValue("root.field3", 55, out _, out _);

            //// "array1": [ 1, 2, 3 ]    =>"array1": [ 1, 2, 666 ]
            //dataAppManagement.ModifyValue("root.array1.[2]", 666, out _, out _);

            //// "array1": [ 1, 2, 3 ]    =>"array3": [ 1, 2, 666 ]
            //dataAppManagement.ModifyKey("root.array1","array3", out _, out _);

            ////如果数组元素是类，[索引.该索引键值对的键]   如果数组元素是值   [索引]
            //dataAppManagement.ModifyValue("root.arrayClass.[2:arrayarrayClass].[1]",77, out _, out _);
            //dataAppManagement.ModifyKey("root.arrayClass.[2:arrayarrayClass]","arrayarrayClass1", out _, out _);

            //dataAppManagement.CopyToBeforeDes("root.arrayClass", "root.array2", out _, out _);
            //dataAppManagement.CopyToAfterDes("root.arrayClass", "root.array2", out _, out _);

            //dataAppManagement.DeleteKeyValue("root.arrayClass.[2:arrayarrayClass].[1]", out _, out _);
            //dataAppManagement.DeleteKeyValue("root.arrayClass.[2:arrayarrayClass]", out _, out _);

            //dataAppManagement.MoveToBeforeDes("root.arrayClass", "root.array2", out _, out _);
            //dataAppManagement.MoveToAfterDes("root.arrayClass", "root.array1", out _, out _);
            // dataAppManagement.MoveToAfterDes("root.arrayClass", "root.aaa.bb.3", out _, out _);


            //dataAppManagement.AddKeyValue("root.array2.[]", 44, out _, out _);

            //JProperty jProperty = new JProperty("ss","bb");
            //JObject jObject = new JObject();
            //jObject.Add(jProperty);
            //dataAppManagement.AddKeyValue("root.arrayClass.[]", jObject, out _, out _);

            JProperty jProperty = new JProperty("ss", "ffffffbb");

            dataAppManagement.InsertToAfterDes(jProperty, "root.aaa.bb.3", out _, out _);
            dataAppManagement.InsertToBeforeDes(jProperty, "root.aaa.bb.3", out _, out _);


            var jt = dataAppManagement.GetToken("root.aaa", out _, out _);
            var t = ((JProperty)jt).Value;



            dataAppManagement.SaveFile(@"C:\Users\Public\Desktop\122.json", out _, out _);


        }
    }
}
